package com.iuhao.web.test2;

import java.util.concurrent.TimeUnit;

/**
 * Created by yanhao on 2017/12/25.
 */
public class TestThreadsAndRunnable {
    public static void main(String[] args) {


        try {
            //test1();
            //test2();
            System.out.println(5%2);


        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private static void test2() {

        Runnable runnable = () -> {
            try {
                String name = Thread.currentThread().getName();
                System.out.println("Foo " + name);
                TimeUnit.SECONDS.sleep(1);//模仿并发
                System.out.println("Bar " + name);
            }
            catch (InterruptedException e) {
                e.printStackTrace();
            }
        };
        Thread thread = new Thread(runnable);
        thread.start();
    }


    private static void test1() throws InterruptedException {
        Runnable task = () -> {
            String threadName = Thread.currentThread().getName();
            System.out.println("Hello " + threadName);
        };
        Thread.sleep(2);
        task.run();
        Thread thread = new Thread(task);
        thread.start();
        System.out.println("Done!");
    }
}
